import { BaseService } from '@/base/base.service';
import { pageData } from '@/util/util';
import { Injectable } from '@nestjs/common';
import { rechargeRecord } from '@prisma/client';
import { CreateRechargeRecordDto } from './dto/create-recharge-record.dto';
import { UpdateRechargeRecordDto } from './dto/update-recharge-record.dto';

@Injectable()
export class RechargeRecordService {

  constructor(private readonly baseService: BaseService){}

  async create(createRechargeRecordDto: CreateRechargeRecordDto) {
    await this.baseService.rechargeRecord.create({
      data: {
        ...createRechargeRecordDto
      }
    })
    return '添加成功'
  }

  async findAll() {
    return await this.baseService.rechargeRecord.findMany();
  }

  async findPage(query: any) {
    return await pageData<rechargeRecord>('rechargeRecord', query)
  }

  async findOne(id: string) {
    return await this.baseService.rechargeRecord.findUnique({
      where: {
        id
      }
    })
  }

  async update(id: string, updateRechargeRecordDto: UpdateRechargeRecordDto) {
    await this.baseService.rechargeRecord.update({
      where: {
        id
      },
      data: updateRechargeRecordDto
    })
    return '修改成功'
  }

  async remove(id: string) {
    await this.baseService.rechargeRecord.delete({
      where: {
        id
      }
    })
    return '删除成功'
  }

  manyRemove(idList: string[]) {
    idList.forEach(async item => {
      await this.remove(item)
    })
    return '删除成功'
  }
}
